package persistence;

import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;

import model.AlarmLog;

import communication.FireAlarm;
import communication.GasAlarm;
import communication.RadiationAlarm;

/**
 * Log panel
 * @author Adrien Ledeul
 * @version 0.1
 */
public class LogPanel extends JPanel
{
	private static final long serialVersionUID = 1L;
	
	private ArrayList<AlarmLog> log;

	/**
	 * Constructors
	 * 
	 */
	public LogPanel(ArrayList<AlarmLog> log)
	{
		super();
		this.log = log;
		this.build();
	}

	/**
	 * Build the panel
	 */
	private void build()
	{
		int fireAlarmCpt = 0;
		int gasAlarmCpt = 0;
		int radiationAlarmCpt = 0;
		
		this.setLayout(new GridLayout(3,1));
		
        for (AlarmLog l : log)
        {
        	if(l.getAlarm() instanceof FireAlarm)
        		fireAlarmCpt++;
        	if(l.getAlarm() instanceof GasAlarm)
        		gasAlarmCpt++;
        	if(l.getAlarm() instanceof RadiationAlarm)
        		radiationAlarmCpt++;
        }

		this.add(new JLabel(fireAlarmCpt + " fire alarm(s)"));
		this.add(new JLabel(gasAlarmCpt + " gas alarm(s)"));
		this.add(new JLabel(radiationAlarmCpt + " radiation alarm(s)"));
	}
}
